<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户token" prop="token">
        <el-input
          v-model="queryParams.token"
          placeholder="请输入用户token"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="取货类型" prop="pickupType">
        <el-input
          v-model="queryParams.pickupType"
          placeholder="请输入取货类型"
          clearable
          @keyup.enter.native="handleQuery"
          style="display: none"
        />
      </el-form-item>
      <el-form-item label="优惠码" prop="couponCode">
        <el-input
          v-model="queryParams.couponCode"
          placeholder="请输入优惠码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市ID" prop="cityId">
        <el-input
          v-model="queryParams.cityId"
          placeholder="请输入城市ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="活动code" prop="activityCode">
        <el-input
          v-model="queryParams.activityCode"
          placeholder="请输入活动code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="访问来源" prop="sourceAppName">
        <el-input
          v-model="queryParams.sourceAppName"
          placeholder="请输入访问来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源平台" prop="sourcePlatform">
        <el-input
          v-model="queryParams.sourcePlatform"
          placeholder="请输入来源平台"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="爱回收" prop="utmAhs">
        <el-input
          v-model="queryParams.utmAhs"
          placeholder="请输入爱回收"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="目标ID" prop="distinctId">
        <el-input
          v-model="queryParams.distinctId"
          placeholder="请输入目标ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="内部来源" prop="innerSource">
        <el-input
          v-model="queryParams.innerSource"
          placeholder="请输入内部来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信机器人key" prop="wxBotKey">
        <el-input
          v-model="queryParams.wxBotKey"
          placeholder="请输入微信机器人key"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通知次数" prop="wxBotNotiNum">
        <el-input
          v-model="queryParams.wxBotNotiNum"
          placeholder="请输入通知次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数1" prop="param1">
        <el-input
          v-model="queryParams.param1"
          placeholder="请输入参数1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数2" prop="param2">
        <el-input
          v-model="queryParams.param2"
          placeholder="请输入参数2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数3" prop="param3">
        <el-input
          v-model="queryParams.param3"
          placeholder="请输入参数3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数4" prop="param4">
        <el-input
          v-model="queryParams.param4"
          placeholder="请输入参数4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数5" prop="param5">
        <el-input
          v-model="queryParams.param5"
          placeholder="请输入参数5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数6" prop="param6">
        <el-input
          v-model="queryParams.param6"
          placeholder="请输入参数6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数7" prop="param7">
        <el-input
          v-model="queryParams.param7"
          placeholder="请输入参数7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数8" prop="param8">
        <el-input
          v-model="queryParams.param8"
          placeholder="请输入参数8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数9" prop="param9">
        <el-input
          v-model="queryParams.param9"
          placeholder="请输入参数9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数10" prop="param10">
        <el-input
          v-model="queryParams.param10"
          placeholder="请输入参数10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:ahsconfig:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:ahsconfig:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:ahsconfig:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:ahsconfig:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ahsconfigList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="用户token" align="center" prop="token" />
      <el-table-column label="收获地址ID" align="center" prop="addressId" />
      <el-table-column label="地址描述" align="center" prop="addressDesc" />
      <el-table-column label="取货类型" align="center" prop="pickupType" />
      <el-table-column label="优惠码" align="center" prop="couponCode" />
      <el-table-column label="城市ID" align="center" prop="cityId" />
      <el-table-column label="活动code" align="center" prop="activityCode" />
      <el-table-column label="访问来源" align="center" prop="sourceAppName" />
      <el-table-column label="来源平台" align="center" prop="sourcePlatform" />
      <el-table-column label="爱回收" align="center" prop="utmAhs" />
      <el-table-column label="目标ID" align="center" prop="distinctId" />
      <el-table-column label="内部来源" align="center" prop="innerSource" />
      <el-table-column label="微信机器人key" align="center" prop="wxBotKey" />
      <el-table-column label="通知次数" align="center" prop="wxBotNotiNum" />
      <el-table-column label="参数1" align="center" prop="param1" />
      <el-table-column label="参数2" align="center" prop="param2" />
      <el-table-column label="参数3" align="center" prop="param3" />
      <el-table-column label="参数4" align="center" prop="param4" />
      <el-table-column label="参数5" align="center" prop="param5" />
      <el-table-column label="参数6" align="center" prop="param6" />
      <el-table-column label="参数7" align="center" prop="param7" />
      <el-table-column label="参数8" align="center" prop="param8" />
      <el-table-column label="参数9" align="center" prop="param9" />
      <el-table-column label="参数10" align="center" prop="param10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:ahsconfig:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:ahsconfig:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改爱回收配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户token" prop="token">
          <el-input v-model="form.token" placeholder="请输入用户token" />
        </el-form-item>
        <el-form-item label="取货类型" prop="pickupType">
          <el-input v-model="form.pickupType" placeholder="请输入取货类型" />
        </el-form-item>
        <el-form-item label="优惠码" prop="couponCode">
          <el-input v-model="form.couponCode" placeholder="请输入优惠码" />
        </el-form-item>
        <el-form-item label="城市ID" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入城市ID" />
        </el-form-item>
        <el-form-item label="活动code" prop="activityCode">
          <el-input v-model="form.activityCode" placeholder="请输入活动code" />
        </el-form-item>
        <el-form-item label="访问来源" prop="sourceAppName">
          <el-input v-model="form.sourceAppName" placeholder="请输入访问来源" />
        </el-form-item>
        <el-form-item label="来源平台" prop="sourcePlatform">
          <el-input v-model="form.sourcePlatform" placeholder="请输入来源平台" />
        </el-form-item>
        <el-form-item label="爱回收" prop="utmAhs">
          <el-input v-model="form.utmAhs" placeholder="请输入爱回收" />
        </el-form-item>
        <el-form-item label="目标ID" prop="distinctId">
          <el-input v-model="form.distinctId" placeholder="请输入目标ID" />
        </el-form-item>
        <el-form-item label="内部来源" prop="innerSource">
          <el-input v-model="form.innerSource" placeholder="请输入内部来源" />
        </el-form-item>
        <el-form-item label="微信机器人key" prop="wxBotKey">
          <el-input v-model="form.wxBotKey" placeholder="请输入微信机器人key" />
        </el-form-item>
        <el-form-item label="通知次数" prop="wxBotNotiNum">
          <el-input v-model="form.wxBotNotiNum" placeholder="请输入通知次数" />
        </el-form-item>
        <el-form-item label="参数1" prop="param1">
          <el-input v-model="form.param1" placeholder="请输入参数1" />
        </el-form-item>
        <el-form-item label="参数2" prop="param2">
          <el-input v-model="form.param2" placeholder="请输入参数2" />
        </el-form-item>
        <el-form-item label="参数3" prop="param3">
          <el-input v-model="form.param3" placeholder="请输入参数3" />
        </el-form-item>
        <el-form-item label="参数4" prop="param4">
          <el-input v-model="form.param4" placeholder="请输入参数4" />
        </el-form-item>
        <el-form-item label="参数5" prop="param5">
          <el-input v-model="form.param5" placeholder="请输入参数5" />
        </el-form-item>
        <el-form-item label="参数6" prop="param6">
          <el-input v-model="form.param6" placeholder="请输入参数6" />
        </el-form-item>
        <el-form-item label="参数7" prop="param7">
          <el-input v-model="form.param7" placeholder="请输入参数7" />
        </el-form-item>
        <el-form-item label="参数8" prop="param8">
          <el-input v-model="form.param8" placeholder="请输入参数8" />
        </el-form-item>
        <el-form-item label="参数9" prop="param9">
          <el-input v-model="form.param9" placeholder="请输入参数9" />
        </el-form-item>
        <el-form-item label="参数10" prop="param10">
          <el-input v-model="form.param10" placeholder="请输入参数10" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAhsconfig, getAhsconfig, delAhsconfig, addAhsconfig, updateAhsconfig } from "@/api/system/ahsconfig";

export default {
  name: "Ahsconfig",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 爱回收配置表格数据
      ahsconfigList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        token: null,
        addressId: null,
        addressDesc: null,
        pickupType: null,
        couponCode: null,
        cityId: null,
        activityCode: null,
        sourceAppName: null,
        sourcePlatform: null,
        utmAhs: null,
        distinctId: null,
        innerSource: null,
        wxBotKey: null,
        wxBotNotiNum: null,
        param1: null,
        param2: null,
        param3: null,
        param4: null,
        param5: null,
        param6: null,
        param7: null,
        param8: null,
        param9: null,
        param10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询爱回收配置列表 */
    getList() {
      this.loading = true;
      listAhsconfig(this.queryParams).then(response => {
        this.ahsconfigList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        token: null,
        addressId: null,
        addressDesc: null,
        pickupType: null,
        couponCode: null,
        cityId: null,
        activityCode: null,
        sourceAppName: null,
        sourcePlatform: null,
        utmAhs: null,
        distinctId: null,
        innerSource: null,
        wxBotKey: null,
        wxBotNotiNum: null,
        param1: null,
        param2: null,
        param3: null,
        param4: null,
        param5: null,
        param6: null,
        param7: null,
        param8: null,
        param9: null,
        param10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加爱回收配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAhsconfig(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改爱回收配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAhsconfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAhsconfig(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除爱回收配置编号为"' + ids + '"的数据项？').then(function() {
        return delAhsconfig(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/ahsconfig/export', {
        ...this.queryParams
      }, `ahsconfig_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
